package com.rwlai.dianshang.domain;

import com.qunchuang.bos.BaseEntity;
import com.qunchuang.bos.Bostype;
import com.rwlai.dianshang.ProductException;
import lombok.Data;

import javax.persistence.Entity;

/**
 * Created by liutim on 2017/11/28.
 */

@Entity
@Bostype("A01")
@Data
public class Product extends BaseEntity{
    public String getName() {
        return name;
    }

    private String name;
    private long price;
    private int instock;
    private String type;
    private String merchant;


    public Product(String name, long price, int instock, String type, String merchant) {
        this.name = name;
        this.price = price;
        this.instock = instock;
        this.type = type;
        this.merchant = merchant;
    }

    public Product() {
    }




    public void changeStockByDelta(int delta){
        if(instock+delta<0){
            throw new ProductException("存库不够！");
        }
        this.instock=this.instock+delta;
    }

}
